package com.hx.base.others;

/**
 * @author jxlgcmh
 * @date 2020-03-15 10:45
 * @description
 */
public class GetFinalValue implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new GetFinalValue());
        Thread t2 = new Thread(new GetFinalValue());
        t1.start();
        t2.start();

    }

    @Override
    public void run() {
        int a = 0;
        boolean isOdd = false;
        for (int i = 1; i <= 2; ++i) {
            if (i % 2 == 1) {
                isOdd = true;
            } else {
                isOdd = false;
            }
            a += i * (isOdd ? 1 : -1);

            //first   t1,a=0+1=1  t1 a=1+2*(-1)=-1;
            //        t2,a=0+1=1  t2 a=1+2*(-1)=-1

            // second  t1,a=0+1=1;              t1 a=2+2*(-1)=0;
            //                     t2,a=1+1=2;                   t2 a=0+2*(-1)=-2

            // third   t1,a=0+1=1;               t1 a=2+2*(-1)=0;
            //                      t2,a=1+1=2;  t2=2+2*(-1)=0;


        }
        System.out.println(a);
    }
}
